Imports System.Windows.Forms
Imports Vintasoft.Imaging
Imports Vintasoft.Pdf
Imports Vintasoft.Pdf.Content.ImageExtraction
Imports Vintasoft.Pdf.Tree

Namespace Pdf
	Public Partial Class ViewContentImageForm
		Inherits Form

		#Region "Fields"

		Private _contentImage As ContentImage
		Private _zoom As Single
		Private _focusedImage As VintasoftImage
		Private _focusedPage As PdfPage


		#End Region



		#Region "Constructor"

		Public Sub New(contentImage As ContentImage, zoom As Single)
			Me.New(contentImage, zoom, Nothing, Nothing)
		End Sub

		Public Sub New(contentImage As ContentImage, zoom As Single, focusedImage As VintasoftImage, focusedPage As PdfPage)
			InitializeComponent()
			_zoom = zoom
			_focusedImage = focusedImage
			_focusedPage = focusedPage
			_contentImage = contentImage
			imageViewer.Image = _contentImage.RenderImage(zoom)
			compressionLabel.Text = String.Format(compressionLabel.Text, _contentImage.ImageResource.Compression)
			compressedSizeLabel.Text = String.Format(compressedSizeLabel.Text, _contentImage.ImageResource.Length)
			originalSizelabel.Text = String.Format(originalSizelabel.Text, _contentImage.ImageResource.Width, _contentImage.ImageResource.Height)
			Dim region As RegionF = _contentImage.Region
			LTlabel.Text = String.Format(LTlabel.Text, region.LeftTop.X, region.LeftTop.Y)
			LBlabel.Text = String.Format(LBlabel.Text, region.LeftBottom.X, region.LeftBottom.Y)
			RTlabel.Text = String.Format(RTlabel.Text, region.RightTop.X, region.RightTop.Y)
			RBlabel.Text = String.Format(RBlabel.Text, region.RightBottom.X, region.RightBottom.Y)
		End Sub

		#End Region



		#Region "Methods"

		Private Sub originalImageRadioButton_CheckedChanged(sender As Object, e As EventArgs)
			If originalImageRadioButton.Checked Then
				Dim img As VintasoftImage = imageViewer.Image
				imageViewer.Image = _contentImage.ImageResource.GetImage()
				If img IsNot Nothing Then
					img.Dispose()
				End If
			End If
		End Sub

		Private Sub transformedImageRadioButton_CheckedChanged(sender As Object, e As EventArgs)
			If transformedImageRadioButton.Checked Then
				Dim img As VintasoftImage = imageViewer.Image
				imageViewer.Image = _contentImage.RenderImage(_zoom)
				If img IsNot Nothing Then
					img.Dispose()
				End If
			End If
		End Sub

		Private Sub saveAsButton_Click(sender As Object, e As EventArgs)
			If saveFileDialog.ShowDialog() = DialogResult.OK Then
				imageViewer.Image.Save(saveFileDialog.FileName)
			End If
		End Sub

		Private Sub viewResourceButton_Click(sender As Object, e As EventArgs)
			Dim resourcesViewer As New ResourcesViewerForm(_contentImage.ImageResource, _focusedImage, _focusedPage)
			resourcesViewer.ShowDialog()
		End Sub

		#End Region

	End Class
End Namespace
